﻿Imports DTO
Imports BUS

Public Class fmTraCuuPhieuThue
    Private ctptCrt As CTPhieuThueCrt
    Private Sub CapNhatTieuChuanTraCuu(ByVal bUpdated As Boolean)
        If (bUpdated) Then
            If (txtMaCTPT.Text <> "") Then
                ctptCrt.MaCTPhieuThue = Integer.Parse(txtMaCTPT.Text)
            Else
                ctptCrt.MaCTPhieuThue = 0
            End If
            ctptCrt.TenKhachHang = txtKhachHang.Text
            ctptCrt.LoaiKhachHang = ComboBoxLoaiKhach.SelectedIndex + 1
            ctptCrt.MaPhieuThue = ComboBoxMaPhieuThieu.Text
            ctptCrt.DiaChi = txtDiaCHi.Text
            ctptCrt.CMND = txtCMDN.Text
            ctptCrt.CheckLoaiKH = chkLoaiKhach.Checked
            ctptCrt.CheckTenKH = chkKhachHang.Checked
            ctptCrt.CheckDiaChi = chkDiaChi.Checked
            ctptCrt.checkCMND = chkCMND.Checked
            ctptCrt.CheckMaPhieuThue = ChMaPhieuThue.Checked

        Else
            If (ctptCrt.MaCTPhieuThue <> 0) Then
                txtMaCTPT.Text = ctptCrt.MaCTPhieuThue.ToString()
            End If
            txtKhachHang.Text = ctptCrt.TenKhachHang
            ComboBoxLoaiKhach.SelectedIndex = ctptCrt.LoaiKhachHang
            ComboBoxMaPhieuThieu.Text = ctptCrt.MaPhieuThue
            ctptCrt.CheckTenKH = chkKhachHang.Checked
            ctptCrt.CheckLoaiKH = chkLoaiKhach.Checked
            ctptCrt.CheckDiaChi = chkDiaChi.Checked
            ctptCrt.checkCMND = chkCMND.Checked
            ctptCrt.CheckMaPhieuThue = ChMaPhieuThue.Checked
        End If
    End Sub
    Private Sub ButtonThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonThoat.Click
        Me.Close()
    End Sub

    Private Sub ButtonTraCuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTraCuu.Click
        Try
            CapNhatTieuChuanTraCuu(True)
            Dim ctptBus As New CTPhieuThueBus()
            Dim dtThuePhong As DataTable
            dtThuePhong = ctptBus.TimKiem(ctptCrt)
            dtgwPhieuThuePhong.DataSource = dtThuePhong
        Catch ex As Exception
            MessageBox.Show(ex.Message)

        End Try
    End Sub

    Private Sub chkKhachHang_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkKhachHang.CheckedChanged
        If (chkKhachHang.Checked) Then
            txtKhachHang.Enabled = True
        Else
            txtKhachHang.Enabled = False
        End If
    End Sub

    Private Sub chkLoaiKhach_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLoaiKhach.CheckedChanged
        If (chkLoaiKhach.Checked) Then
            ComboBoxLoaiKhach.Enabled = True
        Else
            ComboBoxLoaiKhach.Enabled = False
        End If
    End Sub

    Private Sub chkCMND_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCMND.CheckedChanged
        If (chkCMND.Checked) Then
            txtCMDN.Enabled = True
        Else
            txtCMDN.Enabled = False
        End If
    End Sub

    Private Sub chkDiaChi_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDiaChi.CheckedChanged
        If (chkDiaChi.Checked) Then
            txtDiaCHi.Enabled = True
        Else
            txtDiaCHi.Enabled = False
        End If
    End Sub
    Private Sub LoadLoaiPhong()
        Dim lkhBus As New LoaiKhachHangBus()
        Dim ds As List(Of LoaiKhachHangDto)
        ds = lkhBus.LayDanhSach()
        ComboBoxLoaiKhach.DataSource = ds
        ComboBoxLoaiKhach.ValueMember = "MaLoaiKhachHang"    'Chuoi ten property Ma cua doi tuong LopHocDto
        ComboBoxLoaiKhach.DisplayMember = "TenLoaiKhachHang" 'Chuoi ten property Ten cua doi tuong LopHocDto
    End Sub
    Private Sub LoadPhieuThue()
        Dim ptBus As New PhieuThueBus()
        Dim ds As List(Of PhieuThueDto)
        ds = ptBus.LayDanhSach()
        ComboBoxMaPhieuThieu.DataSource = ds
        ComboBoxMaPhieuThieu.ValueMember = "MaPhieuThue"    'Chuoi ten property Ma cua doi tuong LopHocDto
        ComboBoxMaPhieuThieu.DisplayMember = "MaPhieuThue" 'Chuoi ten property Ten cua doi tuong LopHocDto
    End Sub
    Private Sub fmTraCuuPhieuThue_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            LoadLoaiPhong()
            LoadPhieuThue()
            ctptCrt = New CTPhieuThueCrt()
            CapNhatTieuChuanTraCuu(False)
            Dim dtPhong As New DataTable()
            dtgwPhieuThuePhong.DataSource = dtPhong
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ComboBoxMaPhieuThieu_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxMaPhieuThieu.SelectedIndexChanged
        
    End Sub

    Private Sub ChMaPhieuThue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChMaPhieuThue.CheckedChanged
        If (ChMaPhieuThue.Checked) Then
            ComboBoxMaPhieuThieu.Enabled = True
        Else
            ComboBoxMaPhieuThieu.Enabled = False
        End If
    End Sub
End Class